﻿@using Apps.Web.Core;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@{
    ViewBag.Title = "选择作业点";
    Layout = "~/Views/Shared/_Index_LayoutEdit.cshtml";
    var _path = Url.Content("~/");
    List<permModel> perm = null;
}

<div class="mvctool bgb">
     <input id="txtQuery" type="text" class="searchText" />
    @Html.ToolButton("btnQuery", "fa fa-search", Resource.Query,  true)
     @Html.ToolButton("btnClear", "fa fa-trash", Resource.Clear,  false)
    @Html.ToolButton("btnReturn", "fa fa-reply", Resource.Reply, false)  <span style="line-height:26px;float:right;margin-right:5px;" id="selCount"></span>
</div>
<table>
    <tr>
        <td style="vertical-align: top; width: 38%;">
            @Html.Raw(ViewBag.TacheTree)
        </td>
        <td style="vertical-align: top;padding: 3px; width: 60%;">
            <table id="NodeList"></table>
        </td>
    </tr>
</table>
<script type="text/javascript">
    var mykey = getUrlParam("key", "");
    var myval = getUrlParam("val", "");

    function getSelected() {
        var node = $('#StructTree').tree('getSelected');
        if (node) {
            var id = node.attributes.id;
          
            $("#NodeList").datagrid("load", { tacheid: id });
        }
    }

    $(function () {
        $("#btnQuery").click(function () {
            var queryStr = $("#txtQuery").val();
            if (queryStr == null) {
                queryStr = "%";
            }
            $("#NodeList").datagrid("load", { tacheid: '', queryStr: queryStr });
        });

        $("#btnClear").click(function () {
            $("input[type='radio']").prop("checked", false);
            //window.parent.SetSelResult("", "")
            SetValue("", "");
            $("#selCount").html("已经选择了 0 作业点");
        });

        $('#NodeList').datagrid({
            url: '@(_path)PUB/OF_NODE/GetSelList?tacheid=',
            width: SetGridWidthSub(190),
            methord: 'post',
            height: SetGridHeightSub(46),
            fitColumns: true,
            sortName: 'NODE_ID',
            sortOrder: 'desc',
            idField: 'NODE_ID',
            pageSize: 12,
            pageList: [12, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            columns: [[ 
                { field: 'NODE_ID', title: '节点编号', width: 80,hidden:true },
                { field: 'TACHE_IDName', title: '环节名称', width: 80, sortable: true }, 
                { field: 'NODE_NAME', title: '节点名称', width: 80,sortable:true },
                { field: 'ENABLED', title: '是否启用', width: 80, sortable: true, formatter: function (value) { return EnableFormatter(value) } },
                { field: 'POSTION', title: '双向进出设备', width: 100, sortable: true, formatter: function (value) { return EnableFormatterNember(value) } },
                { field: 'NODE_CODE', title: '匹配码', width: 80,sortable:true,formatter:@Html.Raw(Apps.Common.EnumMvcHelper.GridFormatterFunc<Wantn.FIS.Enum.Node>("")) },
                { field: 'Flag', title: '选择', width: 80}
            ]],
            onLoadSuccess: function () {
                var rows = $("#NodeList").datagrid("getRows");
                for (var i = 0; i < rows.length; i++) {
                    //获取每一行的数据
                    $('#NodeList').datagrid('beginEdit', i);
                }
                //获得已经选择的值
                var arrVal;
                if (mykey == "") {
                    arrVal = window.parent.GetSelResult();
                }
                else {
                    arrVal = window.parent.GetSelResult(mykey, myval);
                }
                if (arrVal[0]!="")
                {
                    var arr = new Array();
                    arr = arrVal[0].split(',');
                    for (var i = 0; i < arr.length; i++)
                    {
                        $("#cb_" + arr[i]).prop("checked",true);
                    }
                    $("#selCount").html("已经选择了 " + arr.length + " 作业点");
                }

            }
        });
        $("#btnReturn").click(function () {
            window.parent.frameReturnByClose();
        });
    });
</script>
 
<script type="text/javascript">
    function SetValue(id,name)
    {
        if (mykey == "") {
            window.parent.SetSelResult(id, name);
        }
        else {
            window.parent.SetSelResult(id, name, mykey, myval);
        }
        $("#selCount").html("已经选择了 1 作业点");
    }
</script>

 